package com.atguigu.tingshu.user.strategy.impl;

import com.atguigu.tingshu.model.user.UserPaidAlbum;
import com.atguigu.tingshu.user.mapper.UserPaidAlbumMapper;
import com.atguigu.tingshu.user.strategy.ItemTypeStrategy;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service(value = "1001")
public class AlbumStrategy implements ItemTypeStrategy {

    @Autowired
    private UserPaidAlbumMapper userPaidAlbumMapper;
    @Override
    public void savePaidRecord(UserPaidRecordVo userPaidRecordVo) {
        // 先查询是否有购买记录;
        //oolean result = userInfoService.isPaidAlbum(userPaidRecordVo.getItemIdList().get(0), userPaidRecordVo.getUserId());
        UserPaidAlbum userPaidAlbumOne = userPaidAlbumMapper.selectOne(new LambdaQueryWrapper<UserPaidAlbum>()
                .eq(UserPaidAlbum::getAlbumId, userPaidRecordVo.getItemIdList().get(0))
                .eq(UserPaidAlbum::getUserId, userPaidRecordVo.getUserId()));
        // 有购买记录直接返回
        if (null != userPaidAlbumOne) {
            return;
        }

        UserPaidAlbum userPaidAlbum = new UserPaidAlbum();
        userPaidAlbum.setOrderNo(userPaidRecordVo.getOrderNo());
        userPaidAlbum.setUserId(userPaidRecordVo.getUserId());
        //  专辑Id 声音Id vip_service_config.id ==> order_detial.item_id;
        userPaidAlbum.setAlbumId(userPaidRecordVo.getItemIdList().get(0));
        //  添加购买专辑信息;
        userPaidAlbumMapper.insert(userPaidAlbum);

    }
}
